package com.bstek.demo.urule.client;

import com.bstek.demo.urule.client.model.OrderBillingAmount;
import com.bstek.urule.Utils;
import com.bstek.urule.runtime.KnowledgePackage;
import com.bstek.urule.runtime.KnowledgeSession;
import com.bstek.urule.runtime.KnowledgeSessionFactory;
import com.bstek.urule.runtime.service.KnowledgeService;
import com.bstek.frame.model.ApiResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


/**
 * @Title: OrderBillingAmountController
 * @Package: com.bstek.demo.orderBillingAmount
 * @Description:
 * @Author: zxq
 * @Date: 2023/9/14 - 15:56
 */
@RestController
@RequestMapping("urule")
public class OrderBillingAmountController {

    @RequestMapping("orderBillingAmount")
    public ApiResult<?> OrderBillingAmount() throws IOException {
        //创建一个KnowledgeSession对象
        KnowledgeService knowledgeService = (KnowledgeService) Utils.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
        KnowledgePackage knowledgePackage = knowledgeService.getKnowledge("601");
        KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);

        OrderBillingAmount orderBillingAmount = new OrderBillingAmount();
        orderBillingAmount.setOrderAmountStageFee(40000);
        orderBillingAmount.setVendorCount(2);
        orderBillingAmount.setPaymentMethod("根据厂商数量");

        session.insert(orderBillingAmount);

//        Map<String, Object> param = new HashMap<>();
//        param.put("account", orderBillingAmount);
//
//        session.fireRules(param);
        session.fireRules();
        System.out.println("orderBillingAmount:"+orderBillingAmount);
//        Object account = session.getParameter("account");

        return ApiResult.success(orderBillingAmount);    }

}
